package com.example.viewmodedemo;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import java.util.ArrayList;
import java.util.List;

public class MainViewModel extends ViewModel {

    private MutableLiveData<List<String>> list;

    public LiveData<List<String>> getList(){
        if(list==null){
            list = new MutableLiveData<>();
        }
        return list;
    }

    public void add(String str){
        if(list!=null){
            List<String> strList = null;
            if(list.getValue()==null){
                strList = new ArrayList<>();
            }else{
                strList = list.getValue();
            }
            strList.add(str);
            list.postValue((strList));
        }

    }
}
